The papyrus source is pretty messy, sorry.

The SKSE plugin source is a bit better organized, and you can find it on GitHub:

https://github.com/egocarib/EnchantedArsenal